/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef __L_SIGNED_MEASUREMENT_H__
#define __L_SIGNED_MEASUREMENT_H__

#include <string_view>
#include <lua.hpp>
#include "luawrapper.h"
#include "common.h"
#include "measurements/measurement.h"

class LSignedMeasurement {
public:
    string   version;
    string   hashAlgorithm;
    string   signAlgorithm;
    string   publicKey;
    string   measurement;

    LSignedMeasurement(const string& version, const string& hashAlgorithm, const string& signAlgorithm,
        const string& publicKey, const string& measurement)
    {
        this->version       = version;
        this->hashAlgorithm = hashAlgorithm;
        this->signAlgorithm = signAlgorithm;
        this->publicKey     = publicKey;
        this->measurement   = measurement;
    };
    ~LSignedMeasurement() = default;

    std::string_view get_version() const
    {
        return this->version;
    }

    std::string_view get_hash_algo() const
    {
        return this->hashAlgorithm;
    }

    std::string_view get_sign_algo() const
    {
        return this->signAlgorithm;
    }

    std::string_view get_public_key() const
    {
        return this->publicKey;
    }

    std::string_view get_measurement() const
    {
        return this->measurement;
    }

    static void register_to(lua_State *L, luawrap::stack_table &t)
    {
        luawrap::restore_stack_top _s(L);

        auto cls = luawrap::lua_class<LSignedMeasurement>(L);
        cls.def_property("version", c_func_wrap(L, LSignedMeasurement::get_version));
        cls.def_property("hashAlgorithm", c_func_wrap(L, LSignedMeasurement::get_hash_algo));
        cls.def_property("signAlgorithm", c_func_wrap(L, LSignedMeasurement::get_sign_algo));
        cls.def_property("publicKey", c_func_wrap(L, LSignedMeasurement::get_public_key));
        cls.def_property("measurement", c_func_wrap(L, LSignedMeasurement::get_measurement));

        t.set("SignedMeasurement", cls);
    }
};

#endif // __L_SIGNED_MEASUREMENT_H__